package com.hsp.Demo_04_modifier;

import java.math.BigDecimal;

public class Demo_01 {
    public static void main(String[] args) {
        /*
        不能随便查看年龄、工资等隐私，并对年龄进行合理验证。
        年龄： 必须在0-120岁
        工资不能直接查看，
        name的长度必须在2-6之间。
         */

        A0401 a0401 = new A0401();
        a0401.setAge(-19);
        a0401.setName("小");
    }
}

class A0401 {
    private String name;
    private int age;
    private BigDecimal salary;

    public void setName(String name) {
        if (name == null || name.length() < 2 || name.length() > 6) {
            System.out.println("名字输入不正确！");
        }
        this.name = name;
    }

    public String getName() {
        return this.name;
    }

    public void setAge(int age) {
        if (age < 0 || age > 120) {
            System.out.println("年龄输入不正确");
        } else {
            this.age = age;
        }
    }

    public int getAge() {
        return this.age;
    }

    public void setSalary(BigDecimal salary) {
        this.salary = salary;
    }

    public BigDecimal getSalary() {
        return this.salary;
    }


}
